package com.party.core.service.wechat.impl;

import com.google.common.base.Strings;
import com.party.common.paging.Page;
import com.party.core.dao.read.wechat.WechatMerchantsReadDao;
import com.party.core.dao.write.wechat.WechatMerchantsWriteDao;
import com.party.core.model.BaseModel;
import com.party.core.model.wechat.WechatMerchants;
import com.party.core.service.wechat.IWechatMerchantsService;
import com.sun.istack.NotNull;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Set;

/**
 * 微信商户服务实现
 * Created by wei.li.
 *
 * @date 2017/12/8 0008
 * @time 14:13
 */

@Service
public class WechatMerchantsService implements IWechatMerchantsService {

    @Autowired
    private WechatMerchantsReadDao wechatMerchantReadDao;

    @Autowired
    private WechatMerchantsWriteDao wechatMerchantWriteDao;


    /**
     * 新增微信商户
     * @param wechatMerchants 微信商户
     * @return 编号
     */
    @Override
    public String insert(WechatMerchants wechatMerchants) {
        BaseModel.preInsert(wechatMerchants);
        boolean result = wechatMerchantWriteDao.insert(wechatMerchants);
        if (result){
            return wechatMerchants.getId();
        }
        return null;
    }

    /**
     * 更新微信商户
     * @param wechatMerchants 微信商户
     * @return 更新结果(true/fale)
     */
    @Override
    public boolean update(WechatMerchants wechatMerchants) {
        return wechatMerchantWriteDao.update(wechatMerchants);
    }

    /**
     * 逻辑删除
     * @param id 实体主键
     * @return 删除结果(true/false)
     */
    @Override
    public boolean deleteLogic(@NotNull String id) {
        if (Strings.isNullOrEmpty(id)){
            return false;
        }
        return wechatMerchantWriteDao.deleteLogic(id);
    }

    /**
     * 物理删除
     * @param id 实体主键
     * @return 删除结果(true/false)
     */
    @Override
    public boolean delete(@NotNull String id) {
        if (Strings.isNullOrEmpty(id)){
            return false;
        }
        return wechatMerchantWriteDao.delete(id);
    }

    /**
     * 批量逻辑删除
     * @param ids 主键集合
     * @return 删除结果(true/false)
     */
    @Override
    public boolean batchDeleteLogic(@NotNull Set<String> ids) {
        if (CollectionUtils.isEmpty(ids)){
            return false;
        }
        return wechatMerchantWriteDao.batchDeleteLogic(ids);
    }

    /**
     * 批量物理删除
     * @param ids 主键集合
     * @return 删除结果(true/false)
     */
    @Override
    public boolean batchDelete(@NotNull Set<String> ids) {
        if (CollectionUtils.isEmpty(ids)){
            return false;
        }
        return wechatMerchantWriteDao.batchDelete(ids);
    }

    /**
     * 获取微信商户
     * @param id 主键
     * @return 微信商户
     */
    @Override
    public WechatMerchants get(String id) {
        return wechatMerchantReadDao.get(id);
    }

    /**
     * 获取系统配置信息
     *
     * @return 系统配置
     */
    @Override
    public WechatMerchants getSystem() {
        return wechatMerchantReadDao.getSystem();
    }

    /**
     * 分页查询
     * @param wechatMerchants
     * @param page 分页信息
     * @return 微信商户列表
     */
    @Override
    public List<WechatMerchants> listPage(WechatMerchants wechatMerchants, Page page) {
        return wechatMerchantReadDao.listPage(wechatMerchants, page);
    }

    /**
     * 查询所有
     * @param wechatMerchants 微信商户
     * @return 微信商户列表
     */
    @Override
    public List<WechatMerchants> list(WechatMerchants wechatMerchants) {
        return wechatMerchantReadDao.listPage(wechatMerchants, null);
    }

    @Override
    public List<WechatMerchants> batchList(@NotNull Set<String> ids, WechatMerchants wechatMerchant, Page page) {
        return null;
    }

    @Override
    public WechatMerchants findBymerchantId(String merchantId) {
        return wechatMerchantReadDao.findByMerchantId(merchantId);
    }

    @Override
    public List<WechatMerchants> listNoRelation(Integer deployType, String memberId) {
        return wechatMerchantReadDao.listNoRelation(deployType, memberId);
    }

    @Override
    public List<WechatMerchants> getMerchant(String memberId) {
        return wechatMerchantReadDao.getMerchant(memberId);
    }
}
